package cn.stylefeng.guns.modular.mallAboutConfig.controller;

import cn.stylefeng.roses.core.base.controller.BaseController;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.beans.factory.annotation.Autowired;
import cn.stylefeng.guns.core.log.LogObjectHolder;
import org.springframework.web.bind.annotation.RequestParam;
import cn.stylefeng.guns.modular.system.model.ConfigAbout;
import cn.stylefeng.guns.modular.mallAboutConfig.service.IConfigAboutService;

import java.util.Date;

/**
 * 基本信息配置控制器
 *
 * @author fengshuonan
 * @Date 2020-06-02 20:58:24
 */
@Controller
@RequestMapping("/configAbout")
public class ConfigAboutController extends BaseController {

    private String PREFIX = "/mallAboutConfig/configAbout/";

    @Autowired
    private IConfigAboutService configAboutService;

    /**
     * 跳转到基本信息配置首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "configAbout.html";
    }

    /**
     * 跳转到添加基本信息配置
     */
    @RequestMapping("/configAbout_add")
    public String configAboutAdd() {
        return PREFIX + "configAbout_add.html";
    }

    /**
     * 跳转到修改基本信息配置
     */
    @RequestMapping("/configAbout_update/{configAboutId}")
    public String configAboutUpdate(@PathVariable Integer configAboutId, Model model) {
        ConfigAbout configAbout = configAboutService.selectById(configAboutId);
        model.addAttribute("item",configAbout);
        LogObjectHolder.me().set(configAbout);
        return PREFIX + "configAbout_edit.html";
    }

    /**
     * 获取基本信息配置列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(String condition) {
        return configAboutService.selectList(null);
    }

    /**
     * 新增基本信息配置
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(ConfigAbout configAbout) {
        configAbout.setId(0);
        configAbout.setAdddate(new Date());
        configAboutService.insert(configAbout);
        return SUCCESS_TIP;
    }

    /**
     * 删除基本信息配置
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Integer configAboutId) {
        configAboutService.deleteById(configAboutId);
        return SUCCESS_TIP;
    }

    /**
     * 修改基本信息配置
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(ConfigAbout configAbout) {
        configAbout.setAdddate(new Date());
        configAboutService.updateById(configAbout);
        return SUCCESS_TIP;
    }

    /**
     * 基本信息配置详情
     */
    @RequestMapping(value = "/detail/{configAboutId}")
    @ResponseBody
    public Object detail(@PathVariable("configAboutId") Integer configAboutId) {
        return configAboutService.selectById(configAboutId);
    }
}
